
#include "params.h"

using fs::Path;

Params::Params()
{
	autoindex = true;
	nocache = true;
	hideme = true;
	configfile = Path( "web.conf" );
	mimefile = Path( "mime.conf" );
	port = 80;
	root = fs::Path::current_directory();
	index = Path( "index.html" );
}

MimeTypes::MimeTypes(const std::string &default_mime): _default_mime( default_mime )
{
	update( "ai", "application/postscript" );
	update( "aif", "audio/x-aiff" );
	update( "aifc", "audio/x-aiff" );
	update( "aiff", "audio/x-aiff" );
	update( "asc", "text/plain" );
	update( "atom", "application/atom+xml" );
	update( "au", "audio/basic" );
	update( "avi", "video/x-msvideo" );
	update( "bcpio", "application/x-bcpio" );
	update( "bin", "application/octet-stream" );
	update( "bmp", "image/bmp" );
	update( "cdf", "application/x-netcdf" );
	update( "cgm", "image/cgm" );
	update( "class", "application/octet-stream" );
	update( "cpio", "application/x-cpio" );
	update( "cpt", "application/mac-compactpro" );
	update( "csh", "application/x-csh" );
	update( "css", "text/css" );
	update( "dcr", "application/x-director" );
	update( "dif", "video/x-dv" );
	update( "dir", "application/x-director" );
	update( "djv", "image/vnd.djvu" );
	update( "djvu", "image/vnd.djvu" );
	update( "dll", "application/octet-stream" );
	update( "dmg", "application/octet-stream" );
	update( "dms", "application/octet-stream" );
	update( "doc", "application/msword" );
	update( "dtd", "application/xml-dtd" );
	update( "dv", "video/x-dv" );
	update( "dvi", "application/x-dvi" );
	update( "dxr", "application/x-director" );
	update( "eps", "application/postscript" );
	update( "etx", "text/x-setext" );
	update( "exe", "application/octet-stream" );
	update( "ez", "application/andrew-inset" );
	update( "gif", "image/gif" );
	update( "gram", "application/srgs" );
	update( "grxml", "application/srgs+xml" );
	update( "gtar", "application/x-gtar" );
	update( "hdf", "application/x-hdf" );
	update( "hqx", "application/mac-binhex40" );
	update( "htm", "text/html" );
	update( "html", "text/html" );
	update( "ice", "x-conference/x-cooltalk" );
	update( "ico", "image/x-icon" );
	update( "ics", "text/calendar" );
	update( "ief", "image/ief" );
	update( "ifb", "text/calendar" );
	update( "iges", "model/iges" );
	update( "igs", "model/iges" );
	update( "jnlp", "application/x-java-jnlp-file" );
	update( "jp2", "image/jp2" );
	update( "jpe", "image/jpeg" );
	update( "jpeg", "image/jpeg" );
	update( "jpg", "image/jpeg" );
	update( "js", "application/x-javascript" );
	update( "kar", "audio/midi" );
	update( "latex", "application/x-latex" );
	update( "lha", "application/octet-stream" );
	update( "lzh", "application/octet-stream" );
	update( "m3u", "audio/x-mpegurl" );
	update( "m4a", "audio/mp4a-latm" );
	update( "m4b", "audio/mp4a-latm" );
	update( "m4p", "audio/mp4a-latm" );
	update( "m4u", "video/vnd.mpegurl" );
	update( "m4v", "video/x-m4v" );
	update( "mac", "image/x-macpaint" );
	update( "man", "application/x-troff-man" );
	update( "mathml", "application/mathml+xml" );
	update( "me", "application/x-troff-me" );
	update( "mesh", "model/mesh" );
	update( "mid", "audio/midi" );
	update( "midi", "audio/midi" );
	update( "mif", "application/vnd.mif" );
	update( "mov", "video/quicktime" );
	update( "movie", "video/x-sgi-movie" );
	update( "mp2", "audio/mpeg" );
	update( "mp3", "audio/mpeg" );
	update( "mp4", "video/mp4" );
	update( "mpe", "video/mpeg" );
	update( "mpeg", "video/mpeg" );
	update( "mpg", "video/mpeg" );
	update( "mpga", "audio/mpeg" );
	update( "ms", "application/x-troff-ms" );
	update( "msh", "model/mesh" );
	update( "mxu", "video/vnd.mpegurl" );
	update( "nc", "application/x-netcdf" );
	update( "oda", "application/oda" );
	update( "ogg", "application/ogg" );
	update( "pbm", "image/x-portable-bitmap" );
	update( "pct", "image/pict" );
	update( "pdb", "chemical/x-pdb" );
	update( "pdf", "application/pdf" );
	update( "pgm", "image/x-portable-graymap" );
	update( "pgn", "application/x-chess-pgn" );
	update( "pic", "image/pict" );
	update( "pict", "image/pict" );
	update( "png", "image/png" );
	update( "pnm", "image/x-portable-anymap" );
	update( "pnt", "image/x-macpaint" );
	update( "pntg", "image/x-macpaint" );
	update( "ppm", "image/x-portable-pixmap" );
	update( "ppt", "application/vnd.ms-powerpoint" );
	update( "ps", "application/postscript" );
	update( "qt", "video/quicktime" );
	update( "qti", "image/x-quicktime" );
	update( "qtif", "image/x-quicktime" );
	update( "ra", "audio/x-pn-realaudio" );
	update( "ram", "audio/x-pn-realaudio" );
	update( "ras", "image/x-cmu-raster" );
	update( "rdf", "application/rdf+xml" );
	update( "rgb", "image/x-rgb" );
	update( "rm", "application/vnd.rn-realmedia" );
	update( "roff", "application/x-troff" );
	update( "rtf", "text/rtf" );
	update( "rtx", "text/richtext" );
	update( "sgm", "text/sgml" );
	update( "sgml", "text/sgml" );
	update( "sh", "application/x-sh" );
	update( "shar", "application/x-shar" );
	update( "silo", "model/mesh" );
	update( "sit", "application/x-stuffit" );
	update( "skd", "application/x-koan" );
	update( "skm", "application/x-koan" );
	update( "skp", "application/x-koan" );
	update( "skt", "application/x-koan" );
	update( "smi", "application/smil" );
	update( "smil", "application/smil" );
	update( "snd", "audio/basic" );
	update( "so", "application/octet-stream" );
	update( "spl", "application/x-futuresplash" );
	update( "src", "application/x-wais-source" );
	update( "sv4cpio", "application/x-sv4cpio" );
	update( "sv4crc", "application/x-sv4crc" );
	update( "svg", "image/svg+xml" );
	update( "swf", "application/x-shockwave-flash" );
	update( "t", "application/x-troff" );
	update( "tar", "application/x-tar" );
	update( "tcl", "application/x-tcl" );
	update( "tex", "application/x-tex" );
	update( "texi", "application/x-texinfo" );
	update( "texinfo", "application/x-texinfo" );
	update( "tif", "image/tiff" );
	update( "tiff", "image/tiff" );
	update( "tr", "application/x-troff" );
	update( "tsv", "text/tab-separated-values" );
	update( "txt", "text/plain" );
	update( "ustar", "application/x-ustar" );
	update( "vcd", "application/x-cdlink" );
	update( "vrml", "model/vrml" );
	update( "vxml", "application/voicexml+xml" );
	update( "wav", "audio/x-wav" );
	update( "wbmp", "image/vnd.wap.wbmp" );
	update( "wbmxl", "application/vnd.wap.wbxml" );
	update( "wml", "text/vnd.wap.wml" );
	update( "wmlc", "application/vnd.wap.wmlc" );
	update( "wmls", "text/vnd.wap.wmlscript" );
	update( "wmlsc", "application/vnd.wap.wmlscriptc" );
	update( "wrl", "model/vrml" );
	update( "xbm", "image/x-xbitmap" );
	update( "xht", "application/xhtml+xml" );
	update( "xhtml", "application/xhtml+xml" );
	update( "xls", "application/vnd.ms-excel" );
	update( "xml", "application/xml" );
	update( "xpm", "image/x-xpixmap" );
	update( "xsl", "application/xml" );
	update( "xslt", "application/xslt+xml" );
	update( "xul", "application/vnd.mozilla.xul+xml" );
	update( "xwd", "image/x-xwindowdump" );
	update( "xyz", "chemical/x-xyz" );
	update( "zip", "application/zip" );
}

const std::string MimeTypes::operator[]( const std::string & ext ) const
{
	BaseContainer::const_iterator it = _base.find( ext );
	if( it == _base.end() ){
		return default_mime();
	} else {
		return it->second;
	}
}

void MimeTypes::update( const std::string & ext, const std::string & mime )
{
	_base[ ext ] = mime;
}

void MimeTypes::clear()
{
	_base.clear();
}

void MimeTypes::erase( const std::string & ext )
{
	_base.erase( ext );
}

std::string MimeTypes::default_mime() const
{
	return "text/plain";
}